package gui;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.UIManager;
import java.net.URL;

import com.l2fprod.gui.plaf.skin.Skin;
import com.l2fprod.gui.plaf.skin.SkinLookAndFeel;

public class GuiSkinUtilities {
	
	public static void pickSkin(String skinType) {
		if(skinType.equals("java")) {
			setJavaLookAndFeel();
		}
		else if(skinType.equals("motif")) {
			setMotifLookAndFeel();
		}
		else if(skinType.equals("native")) {
			setNativeLookAndFeel();
		}
		else if(skinType.equals("windows")) {
			setWindowsLookAndFeel();
		}
		else if(skinType.equals("mac")) {
			setMacLookAndFeel();
		}
		else {
			setSkinPack("tigerthemepack.zip");
		}
	}
	
	
	
	public static void setSkinPack(String skinPack) {
		try {
			URL imgURL = ClassLoader.getSystemResource("skin/" + skinPack);
			Skin theSkinToUse = SkinLookAndFeel.loadThemePack(imgURL);
			SkinLookAndFeel.setSkin(theSkinToUse);
			UIManager.setLookAndFeel(new SkinLookAndFeel());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		JFrame.setDefaultLookAndFeelDecorated(true);
		JDialog.setDefaultLookAndFeelDecorated(true);
	}
	
	public static void setNativeLookAndFeel() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch(Exception e) {
			System.out.println("Error setting native LAF: " + e);
		}
	}
	
	public static void setJavaLookAndFeel() {
		try {
			UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
			//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); // Also Java look and feel
		} catch(Exception e) {
			System.out.println("Error setting Java LAF: " + e);
		}
	}
	
	public static void setMotifLookAndFeel() {
		try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
		} catch(Exception e) {
			System.out.println("Error setting Motif LAF: " + e);
		}
	}
	
	public static void setWindowsLookAndFeel() {
		try { // Can be used only on Win32 systems
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch(Exception e) {
			System.out.println("Error setting native LAF: " + e);
		}
	}
	
	public static void setMacLookAndFeel() {
		try { // Can be used only on Mac OS platforms
			UIManager.setLookAndFeel("javax.swing.plaf.mac.MacLookAndFeel");
		} catch(Exception e) {
			System.out.println("Error setting Motif LAF: " + e);
		}
	}
	
}
